home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
graphic
/
rcdsplay.zip
/
IOFUNCS.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-05-18
|
25KB
|
632 lines
{**********************************************************************
Unit : IOFUNCS
Version: 1.8
Purpose: This unit contains useful procedures to simplify IO tasks.
Author : Translated form those of Mike Riebe (MISFUNCS, version 3.3)
by Roger Carlson.
Changes: 5/17/90 (RJC,1.1) - Added the procedures of version 1.7 of
RCGRAF.
5/31/90 (RJC,1,2) - Removed the RLTOSTR, DBLTOSTR, LNGTOSTR,
and INTTOSTR procedures which are more easily implemented
by Turbo Pascal's STR procedure.
6/9/90 (RJC,1.3) - Added graphics mode rdstr procedures and
INTTOSTR.
2/15/91 (RJC,1.4) - Added line feed at end of some procedures.
3/28/91 (RJC,1.5) - Added RLTOSTR funciton and the graphics
mode GRDINT procedure.
5/3/91 (RJC,1.6) - Added graphics mode GRDDBL and GRDREAL
procedures.
5/11/91 (RJC,1.7) - Added the DOS shell command DOS_CMD.
5/18/91 (RJC,1.8) - Added LNGTOSTR function and RDLONGLN
procedure.
***********************************************************************}
UNIT IOFUNCS;
INTERFACE
TYPE STR160 = STRING[160]; STR80 = STRING[80]; STR40 = STRING[40];
STR30 = STRING[30]; STR20 = STRING[20]; STR3 = STRING[3];
PROCEDURE rdrealn(VAR window : TEXT; VAR value : REAL);
PROCEDURE rddbln(VAR window : TEXT; VAR value : DOUBLE);
PROCEDURE rdintln(VAR window : TEXT; VAR value : INTEGER);
PROCEDURE RDLONGLN(VAR WINDOW:TEXT; VAR VALUE:LONGINT);
PROCEDURE rdstr160(VAR window : TEXT; VAR value : STR160);
PROCEDURE rdstr80(VAR WINDOW:TEXT; VAR value:STR80);
PROCEDURE rdstr40(VAR WINDOW:TEXT; VAR value:STR40);
PROCEDURE rdstr30(VAR WINDOW:TEXT; VAR value:STR30);
PROCEDURE rdstr20(VAR window : TEXT; VAR value : STR20);
PROCEDURE rdstr3(VAR window : TEXT; VAR value : STR3);
PROCEDURE rdcharln(VAR window : TEXT; VAR value : CHAR);
PROCEDURE GRDSTR160(VAR VALUE:STR160);
PROCEDURE GRDSTR80(VAR VALUE:STR80);
PROCEDURE GRDSTR40(VAR VALUE:STR40);
PROCEDURE GRDSTR30(VAR VALUE:STR30);
PROCEDURE GRDSTR20(VAR VALUE:STR20);
PROCEDURE GRDSTR3(VAR VALUE:STR3);
PROCEDURE GRDCHAR(VAR VALUE:CHAR);
PROCEDURE GRDINT(VAR VALUE:INTEGER);
PROCEDURE GRDDBL(VAR VALUE:DOUBLE);
PROCEDURE GRDREAL(VAR VALUE:REAL);
FUNCTION CALCINCR(INCR:DOUBLE):DOUBLE;
{This function returns the largest power of 1, 2, or 5 <= INCR and can be
used to calculate round number intervals for labeling of plots. INCR
should be a positive number.}
PROCEDURE ENGNOT(NUMBER:DOUBLE; VAR MANTISSA:DOUBLE; VAR EXPONENT:LONGINT);
{This procedure calculates the engineering notation mantissa and exponent
for the number NUMBER.}
FUNCTION NUMDEC(NUM:DOUBLE):INTEGER;
{Calculates the number of decimals in a number to an accuracy of about 1
part in 1E6}
FUNCTION EXISTS(FILENAME:STR30):BOOLEAN;
PROCEDURE BEEP(HZ:WORD);
FUNCTION INTTOSTR(I:INTEGER):STR80; {Converts an integer to a string.}
FUNCTION LNGTOSTR(I:LONGINT):STR80; {Converts a long integer to a string.}
FUNCTION RLTOSTR(RL:REAL;WIDTH:INTEGER):STR80;
{Converts a real number to a string.}
PROCEDURE DOS_CMD; {executes a dos command}
IMPLEMENTATION
USES CRT, GRAPH, DOS, MATH;
{************************ PROCEDURE DOS_CMD **************************}
PROCEDURE DOS_CMD;
VAR NAME:STR80;
BEGIN
CLRSCR;
WRITE('Command: '); RDSTR80(OUTPUT,NAME); WRITELN;
SWAPVECTORS; EXEC('C:\COMMAND.COM',CONCAT('/C ',NAME)); SWAPVECTORS;
IF DOSERROR<>0 THEN WRITELN('DOS ERROR # ',DOSERROR);
WRITE('Hit <ENTER> to continue.'); READLN;
END;
{******************************************************************************
TITLE: RDREALN(VAR WINDOW:TEXT; VAR VALUE : REAL);
FUNCTION: To provide a mechanism for reading real numbers from the keyboard
as well as provide for keeping the current value of the variable
to be read by inputing a carriage return.
INPUTS: A string of digits including '+','-','.',and 'E' defining a real
value.
OUTPUTS: A new value for a variable unless <CR> was the only character
in the input string.
AUTHOR: M. Riebe 11/17/84
CHANGES: 12/06/84: Fixed procedure for finding starting index so that only
digits are valid.
5/15/85 MTR: Fixed correction procedure to allow backspaces.
6/20/85 RJC: Improved error correction.
10/1/85 MTR: Changed to use RDDBLN and convert to real.
10/30/85 RJC:Fixed so that value unchanged if return is entered.
4/8/90 RJC:Translated to Turbo Pascal.
******************************************************************************}
PROCEDURE RDREALN;
VAR DBLTEMP:DOUBLE;
BEGIN DBLTEMP:=VALUE; RDDBLN(WINDOW,DBLTEMP); VALUE:=DBLTEMP; END;
{******************************************************************************
TITLE: RDDBLN(VAR WINDOW:TEXT; VAR VALUE:DOUBLE)
VERSION: 1.1
FUNCTION: Input of double precision real numbers interactively from the
keyboard.
AUTHOR: RJC 9/29/85
CHANGES: (4/8/90, 1.1, RJC) - Translated to Turbo Pascal. Modified to
prevent reading of spurious characters and backspacing before
the first character.
******************************************************************************}
PROCEDURE RDDBLN;
VAR
CH : CHAR;
I,J,K,L,M,N,POWVAL : INTEGER;
ASCII : ARRAY[1..20] OF INTEGER;
NEG,POWNEG : BOOLEAN;
BEGIN {1}
NEG := FALSE; POWNEG := FALSE; POWVAL := 0; I := 1;
REPEAT
REPEAT CH:=READKEY
UNTIL CH IN ['0'..'9','+','-','D','E','.',CHR(13),CHR(8)];
ASCII[I]:=ORD(CH);
IF (ASCII[I] = 8) THEN BEGIN
IF I<>1 THEN WRITE(WINDOW,CH,' ',CH);
IF I<=2 THEN I:=0 ELSE I:=I-2;
END
ELSE WRITE(WINDOW,CH);
I:=I+1;
UNTIL ORD(CH)=13;
I:=I-1; {leave index at last character}
IF ASCII[1]<>13 THEN BEGIN {2}
VALUE:=0; J:=0; K:=0;
REPEAT J:=J+1 UNTIL ASCII[J] IN [43,45..58];
REPEAT K:=K+1 UNTIL ASCII[K] IN [46,68,69,13];
CASE ASCII[J] OF
43 {+}: J:=J+1;
45 {-}: BEGIN NEG:=TRUE; J:=J+1; END;
END; {CASE}
FOR L:=J TO (K-1) DO VALUE:=VALUE+(ASCII[L]-48)*PWROF10(K-L-1);
IF ASCII[K]=46 THEN BEGIN {'.'}
M := K;
REPEAT M:= M + 1 UNTIL ASCII[M] IN [68,69,13];
FOR N:=K+1 TO M-1 DO VALUE:=VALUE+(ASCII[N]-48)/PWROF10(N-K);
K := M;
END; {IF}
IF ASCII[K] IN [68,69] THEN BEGIN {'D' or 'E'}
CASE ASCII[K+1] OF
43 {+}: K:=K+1;
45 {-}: BEGIN POWNEG:=TRUE; K:=K+1; END;
END; {CASE}
FOR N:=K+1 TO I-1 DO POWVAL:=POWVAL+
(ASCII[N]-48)*ROUND(PWROF10(I-N-1));
END; {IF}
IF NEG THEN VALUE:=VALUE*(-1);
IF POWNEG THEN VALUE := VALUE/PWROF10(POWVAL)
ELSE VALUE := VALUE*PWROF10(POWVAL);
END; {2}
WRITE(WINDOW,CHR($0A)); {line feed}
END; {1}
{******************************************************************************
TITLE: rdintln(VAR WINDOW:TEXT; VAR VALUE:INTEGER);
FUNCTION: To provide a mechanism for reading integers from the keyboard
while providing for keeping the current value of the variable
if a carriage return is input.
INPUTS: A string of digits followed by a <CR> or just a <CR>.
OUTPUTS: A new value for the variable value unless <CR> was the only
character in the input string.
NOTES: Should someday be modified to allow input from any file type,
i.e., not just INPUT.
AUTHOR: M. Riebe 11/17/84
CHANGES: 5/15/85 MTR: Fixed input routine to allow backspaces for
corrections.
6/20/85 RJC: Improved error correction.
5/8/90 RJC: Translated to Turbo Pascal. Added same changes
as versions 1.1 of RDDBLN.
5/18/91 RJC: Corrected number of digits error to allow up to
6 digits.
*